package com.example.demo.easyexcel.controller;

import com.example.demo.easyexcel.db.entity.City;
import com.example.demo.easyexcel.db.repository.CityRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @Author: zjq
 * @Date: create in 2023/5/25 9:37
 */

@Api(tags = {"jpa动态插入与修改"})
@RestController
@RequestMapping("/city")
public class CityController {

    @Autowired
    private CityRepository cityRepository;

    @ApiOperation(value = "编辑、保存数据")
    @PostMapping("/save")
    public void save(@RequestBody City city) {
        Optional<City> a = cityRepository.findById(city.getId());
        a.get().setName(city.getName());
        a.get().setPhoto(city.getPhoto());
        cityRepository.save(a.get());
    }

}
